
package graphics;

import java.util.HashMap;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import willispace.Database;

/**
 * Panel to show key-value properties of entities
 * @author Mateusz
 */
public class PropertiesPanel extends JPanel {
    private HashMap<String, String> properties;
    private HashMap<String, JLabel> labels;
    private ResourceBundle rb;
    
    /**
     * Creates properties panel with specified properites
     * @param properties set of properties to display
     */
    public PropertiesPanel(HashMap<String, String> properties){
        if(properties == null){
            properties = Database.globalProperties;
        }
        
        // call proper properties file
        rb = java.util.ResourceBundle.getBundle("graphics/PropertiesPanel");
        
        setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
        
        this.properties = properties;
        labels = new HashMap<String, JLabel>();
        
        for (Map.Entry<String, String> entry : properties.entrySet()){
            String key = entry.getKey();
            JLabel jl = new JLabel();
            labels.put(key, jl);
            add(jl);
        }
        
    }
    
    /**
     * Updates values of labels
     */
    public void updateLabels(){
        for (Map.Entry<String, String> entry : properties.entrySet()){
            String key = entry.getKey();
            try{
                key = rb.getString(key);
            }
            catch(MissingResourceException ex){
            }
            
            String value = key + " : "+entry.getValue();
            
            labels.get(entry.getKey()).setText(value);
        }
        
        //validate();
    }
            
}
